package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Tower;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/2/23
 */

public class TowerDataListAdapter extends RecyclerAdapter<Tower, TowerDataListAdapter.TowerDataViewHolder> {

    public TowerDataListAdapter(Context context, List<Tower> dataList) {
        super(context, dataList);
    }

    @Override
    public TowerDataViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_tower_data_list, null);
        return new TowerDataViewHolder(view);
    }

    @Override
    public void onBindViewHolder(TowerDataViewHolder holder, int position) {
        holder.bindData(position);
    }

    public class TowerDataViewHolder extends RecyclerAdapter.BaseViewHolder<Tower>{
        @BindView(R.id.tower_name_tv)
        HXTextView towerNameTv;
        @BindView(R.id.tower_num_tv)
        HXTextView towerNumTv;

        public TowerDataViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(int position) {
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            itemView.setLayoutParams(params);
            final Tower tower = dataList.get(position);
            towerNameTv.setText(tower.getName());
            towerNumTv.setText("设备编号：" + tower.getNumber());
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickListener.onClick(tower);
                }
            });
        }
    }
}
